var oSectorBtn = document.querySelector(".sectorBtn");
/* var oSectorModal_div2_box = document.querySelector(".sectorModal_div2_box"); */
var oSectorModal_div1_box_p = document.querySelector(".sectorModal_div1_box p");

var oSectorModal_div2_box_div = document.querySelectorAll(
  ".sectorModal_div2_box div"
);
// console.log(oSectorModal_div2_box_div);

oSectorBtn.addEventListener("click", oSectorBtnFn);
function oSectorBtnFn() {
  $("#sectorModal").modal("hide");
}

// 贸易公司中大盒子
var oSectorModal_div4_box = document.querySelector(".sectorModal_div4_box");
// 点击后贸易公司中的选项后
// 大盒子
var oSectorModal_div5_box = document.querySelector(".sectorModal_div5_box");
var oSectorModal_div5_box_list = document.querySelectorAll(
  ".sectorModal_div5_box_list"
);
var oRadio = document.querySelectorAll("#blankRadio1");
var oSpan = document.querySelectorAll("#sectorModal_div5_box_list_span_style");
var sectorModal_div5_box_p_a = document.querySelector(
  ".sectorModal_div5_box_p a"
);
// 添加内容的盒子
var oSectorModal_div2_box = document.querySelector(".sectorModal_div2_box");
var isNow = 0;
var flog = false;
var addCount = 0;
for (var i = 0; i < oSectorModal_div5_box_list.length; i++) {
  oSectorModal_div5_box_list[i].dataset.indent = i;
  oSectorModal_div5_box_list[i].onclick = function () {
    isNow = this.dataset.indent;

    if (flog == false) {
      var str = oSpan[isNow].innerText;
      var oDiv = document.createElement("div");
      oDiv.innerHTML =
        "<span>" +
        str +
        "</span>" +
        ' <img class="sectorModal_div_box_img1" src="../../images/tjy_img/modal/modal_line.png"> <img class="sectorModal_div_box_img2" src="../../images/tjy_img/modal/modal_x.png">';
      oDiv.classList.add("sectorModal_div_box");
      oSectorModal_div2_box.appendChild(oDiv);
      var oD = oDiv.children[2];
      addCount++;
      // console.log(oD.parentNode.parentNode);
      oD.onclick = function () {
        this.parentNode.parentNode.removeChild(this.parentNode);
        addCount--;
        oSectorModal_div1_box_p.innerText = "已选择：" + addCount;
      };
      oSectorModal_div1_box_p.innerText = "已选择：" + addCount;

      oSpan[isNow].style.color = "#2561ef";
      // 替换的图片
      oRadio[isNow].src = "../../images/tjy_img/modal/modal_radio2.png";
      flog = true;
    } else {
      oSpan[isNow].style.color = "#333333";
      // 原图片
      oRadio[isNow].src = "../../images/tjy_img/modal/modal_radio1.png";
      flog = false;
    }
    // console.log(flog)
  };
}

var count = oSectorModal_div2_box_div.length + addCount;
oSectorModal_div1_box_p.innerText = "已选择：" + count;
/* console.log("count:=" + count);
console.log("addCount:=" + addCount); */

// 删除自定义的元素
for (var i = 0; i < oSectorModal_div2_box_div.length; i++) {
  oSectorModal_div2_box_div[i].onclick = function () {
    this.parentNode.removeChild(this);
    count--;
    oSectorModal_div1_box_p.innerText = "已选择：" + count;
  };
}
sectorModal_div5_box_p_a.addEventListener("click", hideBoxFn);
function hideBoxFn() {
  oSectorModal_div4_box.style.display = "block";
  oSectorModal_div5_box.style.display = "none";
}
var oSectorModal_div4_box_list = document.querySelectorAll(
  ".sectorModal_div4_box_list"
);
for (var i = 0; i < oSectorModal_div4_box_list.length; i++) {
  oSectorModal_div4_box_list[i].onclick = function () {
    oSectorModal_div4_box.style.display = "none";
    oSectorModal_div5_box.style.display = "block";
  };
}

var oSectorModal_div3_box_value = document.querySelector(
  "#sectorModal_div3_box_value"
);
var oSectorModal_input_value = document.querySelector(
  ".sectorModal_input_value"
);
var oSectorBtn = document.querySelector(".sectorBtn");
oSectorBtn.addEventListener("click", valueFn);
function valueFn() {
  // console.log(oSectorModal_div3_box_value.value)
  var str = oSectorModal_div3_box_value.value;
  oSectorModal_input_value.value = str;
  oSectorModal_div3_box_value.value = "";
}
